package com.app.service.impl;

import com.app.mapper.PersonPositionMapper;
import com.app.mapper.RoleMapper;
import com.app.model.PersonPositionModel;
import com.app.model.RoleModel;
import com.app.service.PersonPositionService;
import com.app.service.RoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Primary
public class PersonPositionServiceImpl implements PersonPositionService {
   @Autowired
    PersonPositionMapper personPositionMapper;


    @Override
    public PersonPositionModel selectPosByPid(int personId) {//查主职
        QueryWrapper<PersonPositionModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","department_id","position","is_major").eq("person_id",personId).eq("is_major",1);
        PersonPositionModel model =  personPositionMapper.selectOne(queryWrapper);
        return model;
    }
    @Override
    public PersonPositionModel selectPosById(int id) {//根据id查职务
        QueryWrapper<PersonPositionModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","department_id","position","is_major").eq("id",id);
        PersonPositionModel model =  personPositionMapper.selectOne(queryWrapper);
        return model;
    }

    @Override
    public List<PersonPositionModel> getPositionList(int personId) {
        QueryWrapper<PersonPositionModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","department_id","position","is_major").eq("person_id",personId);
        List<PersonPositionModel> positionModelList = personPositionMapper.selectList(queryWrapper);
        return positionModelList;
    }

    @Override
    public List<PersonPositionModel> listExport(Integer personId) {
        QueryWrapper<PersonPositionModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","department_id","position","is_major").eq("person_id",personId);
        List<PersonPositionModel> positionModelList = personPositionMapper.selectList(queryWrapper);
        return positionModelList;
    }

    @Override
    public void update(PersonPositionModel model) {
        personPositionMapper.updateById(model);
    }

    @Override
    public void insert(PersonPositionModel model) {
        personPositionMapper.insert(model);
    }

    @Override
    public void delete(int id) {
        personPositionMapper.deleteById(id);
    }

    @Override
    public List<PersonPositionModel> selectList() {
        return personPositionMapper.selectList(null);
    }
}
